package sort;

import java.util.Arrays;
import java.util.Random;

public class InsertDemo {
    public static void main(String[] args) {
        int []arr = new int[100000];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt();
        }
        long start = System.currentTimeMillis();
        int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] > arr[i + 1]){
                index = i + 1;
                break;
            }
        }
        for (int i = index; i < arr.length; i++) {
            int j = i;
            while (j > 0 && arr[j - 1] > arr[j]){
                int temp = arr[j];
                arr[j] = arr[j - 1];
                arr[j - 1] = temp;
                j--;
            }
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);//1451
        //System.out.println(Arrays.toString(arr));
    }
}
